1 class Solution
2 {
3 public:
	4 int coinChange(vector<int>&coins, int amount)
		5 {
			10 const int INF = 0x3f3f3f3f;
		11
			12 int n = coins.size();
		13 vector<vector<int>> dp(n + 1, vector<int>(amount + 1));
		14 for (int j = 1; j <= amount; j++) dp[0][j] = INF;
		15 for (int i = 1; i <= n; i++)
			16 for (int j = 0; j <= amount; j++)
			17 {
			18 dp[i][j] = dp[i - 1][j];
			19 if (j >= coins[i - 1])
				20 dp[i][j] = min(dp[i][j], dp[i][j - coins[i - 1]] + 1);
			21 }
		22 return dp[n][amount] >= INF ? -1 : dp[n][amount];
		23 }
	24 };